package com.android.server.actionHandler;

import java.util.Hashtable;

import com.android.client.event.AbstractEvent;
import com.google.gwt.event.shared.EventHandler;

public class ActionHandlerFactory {
	private static final Hashtable<String, String> mapping;
	
	static {
		ActionMappingParser parser = new ActionMappingParser();
		mapping = parser.getMapping();
	}

	private ActionHandlerFactory(){}
	
	@SuppressWarnings("unchecked")
	public static <T extends ActionHandler> T getHanlder(AbstractEvent<? extends EventHandler> action){
		String handlerName = mapping.get(action.getClass().getName());
		try {
			return (T) Class.forName(handlerName).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
}
